package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.unicorn.common.utils.ExcelUtils;
import io.unicorn.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.VaccountmanageEntity;
import io.unicorn.modules.water.service.VaccountmanageService;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2021-05-07 14:06:07
 */
@RestController
@RequestMapping("water/vaccountmanage")
public class VaccountmanageController {
    @Autowired
    private VaccountmanageService vaccountmanageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:vaccountmanage:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = vaccountmanageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{proName}")
    @RequiresPermissions("water:vaccountmanage:info")
    public R info(@PathVariable("proName") String proName){
        VaccountmanageEntity vaccountmanage = vaccountmanageService.getById(proName);

        return R.ok().put("vaccountmanage", vaccountmanage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:vaccountmanage:save")
    public R save(@RequestBody VaccountmanageEntity vaccountmanage){
        vaccountmanageService.save(vaccountmanage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:vaccountmanage:update")
    public R update(@RequestBody VaccountmanageEntity vaccountmanage){
        ValidatorUtils.validateEntity(vaccountmanage);
        vaccountmanageService.updateById(vaccountmanage);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:vaccountmanage:delete")
    public R delete(@RequestBody String[] proNames){
        vaccountmanageService.removeByIds(Arrays.asList(proNames));

        return R.ok();
    }

    @RequestMapping("/export")
    @RequiresPermissions("water:vaccountmanage:list")
    public void export(@RequestParam Map<String, Object> params,
            HttpServletRequest request,
            HttpServletResponse repsonse){
        JSONObject jsonObject = JSONObject.parseObject((String)params.get("params"));
        PageUtils page = vaccountmanageService.queryPage(jsonObject);
        List<?> listEntity = page.getList();

        ExcelUtils.exportXlsx(
                repsonse,
                "export",
                "io.unicorn.modules.water.entity.VaccountmanageEntity",
                listEntity);
    }
}
